import 'package:flutter/material.dart';
import 'res/listData.dart';
void main() => runApp(MyApp());
 
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Material App',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Material App Bar'),
        ),
        body: HomeContent(),
      ),
    );
  }
}

class HomeContent extends StatelessWidget { 
  Widget _getData(context,index){
      return ListTile(
          leading:Image.network(
          listData[index]['imageUrl']
        ),
        title: Text(listData[index]['title']),
        subtitle: Text(listData[index]['author']),
      );
  }
  @override
  Widget build(BuildContext context) {
    // 自动循环以上的数组
    return ListView.builder(
      itemCount:listData.length,
      itemBuilder:this._getData,
    );
  }
}
class Listbuilder extends StatelessWidget {
  List list = new List();
  HomeContent(){
    for (var i = 0; i < 50; i++) {
        this.list.add('我是第$i条');
    }
  }
  @override
  Widget build(BuildContext context) {
    // 自动循环以上的数组
    return ListView.builder(
      itemCount:this.list.length,
      itemBuilder: (context,index){
          return ListTile(
            title: Text(this.list[index]),
          );
      },
    );
  }
}
class ListMapData extends StatelessWidget {
  List <Widget> getData(){ 
    var lists = listData.map((value){
      return ListTile(
        leading:Image.network(
          value['imageUrl']
        ),
        title: Text(value['title']),
        subtitle: Text(value['author']),
      );
    });
    return lists.toList();
  }
  @override
  Widget build(BuildContext context) {
     
    return ListView(
      children: this.getData(),
    );
  }
}
//水平列表
class ListHorizontal extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
     
    return Container(
        height: 300.0,
        child: ListView(
          // 添加滚动方向
          scrollDirection:Axis.horizontal,
          children: <Widget>[
            Container(
              width: 180.0,
              height: 180.0,
              color:Colors.blue
            ),
            Container(
              width: 180.0,
              height: 180.0,
              color:Colors.yellow
            ),
            Container(
              width: 180.0,
              height: 180.0,
              color:Colors.green
            ),
            Container(
              width: 180.0,
              height: 180.0,
              color:Colors.red
            )
          ],
        )
    );
  }
  
}
// 普通图文列表
class DefList extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
     
    return ListView(
      padding: EdgeInsets.all(5),
      children: <Widget>[
        ListTile(
          // leading 可放各种组件
          // leading: Icon(Icons.search,size: 30),
          leading: Image.asset(
            "images/vue.png",
            width: 100.0,
            height: 100.0,
            fit: BoxFit.cover,
          ),
          title: Text("大叔大婶范德萨工地上干活范德萨发放给外人"),
          subtitle: Text("大时代会撒娇客户"),
        )
      ],
    );
  }
}